package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.common.model.RankRule;
import com.msmall.community.common.service.RankRuleManager;

public class RankRuleAction extends HTMLBaseAction{

	private static final long serialVersionUID = 2538314350871147391L;

	private Long ruleId;
	
	private RankRule rule;
	
	private RankRuleManager rankRuleManager;

	public String execute(){
		page.setClazz(RankRule.class);
		page.setOrderBy("rankRuleId");
		page.setOrder("asc");
		page.setPageSize(10);
		rankRuleManager.getPagination(page);
		return SUCCESS;
	}
	
	public String create(){
		rule = null;
		return SUCCESS;
	}
	
	public String update(){
		rule = (RankRule) rankRuleManager.get(RankRule.class, ruleId);
		return SUCCESS;
	}
	public String save(){
		if(rule.getEnabled() == null){
			rule.setEnabled(ConstantDB.UNAVALIABLE);
		}
		rankRuleManager.saveRankRule(rule);
		return execute();
	}
	
	public Long getRuleId() {
		return ruleId;
	}

	public void setRuleId(Long ruleId) {
		this.ruleId = ruleId;
	}

	public RankRule getRule() {
		return rule;
	}

	public void setRule(RankRule rule) {
		this.rule = rule;
	}

	public void setRankRuleManager(RankRuleManager rankRuleManager) {
		this.rankRuleManager = rankRuleManager;
	}
}
